package com.itheima.stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Stream;

public class Demo2 {
    public static void main(String[] args) {
        ArrayList<String > list=new ArrayList<>();
        Collections.addAll(list,"张三丰","张无忌","张翠山","王二麻子","张良","谢广坤");
        list.stream().filter((String s)->{
            boolean start = s.startsWith("张");
            boolean len = s.length() == 3;
            boolean end = s.endsWith("丰");
            return start&&len&&end;
        }).forEach(s-> System.out.println(s));
        //对于流要使用链式编程,每次用每次创建新流,以防止下次会使用--->出现脏流
      /*  Stream<String> list1 = list.stream().limit(5);
       // list1.forEach(System.out::println);
        Stream<String> list2 = list.stream().skip(list.size() - 2);
      //list2.forEach(System.out::println);
        Stream<String> stream3 = Stream.concat(list1, list2);
       // stream3.forEach(System.out::println);
        Stream<String> stream4 = stream3.distinct();
        stream4.forEach(System.out::println);
*/

    }
}
